package com.rongzhe.house.presenter;

import android.content.Intent;

import com.rongzhe.house.entity.Dictionary;
import com.rongzhe.house.internet.DataListener;
import com.rongzhe.house.manager.DictionaryManager;
import com.rongzhe.house.manager.OrderManager;
import com.rongzhe.house.ui.UiControlInterface;
import com.rongzhe.house.ui.activity.OrderActivity;
import com.rongzhe.house.ui.activity.PayTypeActivity;

import java.util.List;

/**
 * Created by huang on 2018/1/4.
 */

public class PayTypePresenter extends BasePresenter {
    public PayTypePresenter(UiControlInterface uiControlInterface) {
        super(uiControlInterface);
    }

    @Override
    public void onCreate() {
        OrderManager.getInstance().setPayWay(null);
    }

    @Override
    public void start(Intent intent) {
        DictionaryManager.getInstance().getDictionaryByType(
                DictionaryManager.DICTIONARY_PAY_TYPE_OPTION, new DataListener<List<Dictionary>>() {
                    @Override
                    public void onSuccess(List<Dictionary> data, String message) {
                        if (data != null && data.size() > 0) {
                            ((PayTypeActivity)getUiControlInterface()).setPayTypeData(data);
                        }
                    }

                    @Override
                    public void onFailed(Throwable error, String message) {

                    }

                    @Override
                    public void onEnd() {

                    }
                });
    }

    public void onPayTypeChoosed(String code) {
        OrderManager.getInstance().setPayType(code);
        Intent itent = new Intent(mContext, OrderActivity.class);
        getUiControlInterface().launchActivity(true, itent);
        getUiControlInterface().finish();
    }
}
